package com.yiba.vpn.protocal.tcpip;

import com.yiba.vpn.utils.CommonMethods;
/**
 * 封装了ICMP ptotocal header
 */
public class ICMPHeader {

    public static final short offset_check_sum =  2;
    public static final short offset_code =  1;
    public static final short offset_type =  0;
    public byte[] mData;
    public int mOffset;

    public ICMPHeader(byte[] data, int offset) {
        this.mData = data;
        this.mOffset = offset;
    }

    public short getCrc() {
        return CommonMethods.readShort(this.mData, this.mOffset + 2);
    }

    public void setCrc(short value) {
        CommonMethods.writeShort(this.mData, this.mOffset + 2, value);
    }

    public int getType() {
        return this.mData[this.mOffset + 0];
    }

    public int getCode() {
        return this.mData[this.mOffset + 1];
    }

    @Override
    public String toString() {
        return String.format("ICMP协议：tyepe=%s,code=%s", getType(),getCode());
    }
}
